import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import remove from '@dfeidao/atom-web/local/remove';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
// import show_loading from '../../atom-web/show-loading';
// import hide_loading from '../../atom-web/hide-loading';
import p001 from './p001';
import p002 from './p002';
import p005 from './p005';
// 查询
export default async function a004(fd: IFeidaoAiBrowserComponent) {
	const name_inp = fd.data.node.querySelector('#tname') as HTMLInputElement;
	const name = name_inp.value;

	const prid = get(fd, 'productid');
	// { $or: [{ field1: value }, { field2: value }] }
	const page_no = 1;
	const page_size = 10;
	let query = {
		filter: {

		}
	} as {
		filter: object;
		page_no: number;
		page_size: number
	};
	if (name) {
		query = {
			filter: {
				$or: [{
					tablename: {
						$regex: '.*' + name + '.*',
						$options: "i"
					}
				}, {
					tabtitle: {
						$regex: '.*' + name + '.*',
						$options: "i"
					}
				}],
				productid: prid
			},
			page_no,
			page_size
		};
	} else {
		query = {
			filter: {
				productid: prid
			},
			page_no,
			page_size
		};
	}
	// console.log(query, '---');
	// debugger;
	// show_loading();
	// const res = await nodejs<{ count: number; dataArray: object[]; page_size: number; page_no: number }>(url, './permissions/role_type_find2', query, false, false);
	const res = await nodejs<{ count: number; dataArray: object[]; page_size: number; page_no: number }>('role-type/zj-000009/s001', query);
	// console.log(res, '000');
	// hide_loading();
	const p2 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const p1 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	const p5 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p005"]');
	if (res.dataArray.length === 0) {
		p1.classList.add('display-n');
		p5.classList.add('display-n');
		p2.classList.remove('display-n');
		render(fd, '', p001, 'p001', 'inner');
		render(fd, '', p002, 'p002', 'inner');
	} else {
		p2.classList.add('display-n');
		p1.classList.remove('display-n');
		p5.classList.remove('display-n');
		render(fd, res.dataArray, p001, 'p001', 'inner');
		res.page_no = page_no;
		res.page_size = page_size;
		render(fd, res, p005, 'p005', 'inner');
	}
	remove(fd, 'tname');
}
